package com.springboot.aspect;

import com.springboot.annotation.SimplePrint;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class SimplePrintAspect {

    @Pointcut("@annotation(com.springboot.annotation.SimplePrint)")
    public void printPointCut(){}

    @Before("printPointCut()")
    public void before(JoinPoint joinPoint){
        System.out.println(".........before......");
        try {
            MethodSignature sign = (MethodSignature) joinPoint.getSignature();
            //获取注解参数
            SimplePrint sp = sign.getMethod().getAnnotation(SimplePrint.class);
            System.out.println("注解参数value:" + sp.value());

        }catch (Throwable throwable){
            throwable.printStackTrace();
        }
        System.out.println(".....end......");
    }

    @After("printPointCut()")
    public void after(){
        System.out.println("完成后执行....");
    }

}
